﻿using System;
using DotNetty.Transport.Channels;
using InkjetControl.bean;
using InkjetControl.codec;
using InkjetControl.NLog;

namespace InkjetControl.events
{
    public delegate void ClientLoginEventHandler(string machineCode, string machineLabel, IChannel channel);
    public delegate void ClientLogoutEventHandler(string machineCode);
    public delegate void ServerSendMsgEventHandler(string machineCode, Message msg);
    public delegate void ClientStatusEventHandler(string machineCode, StatusBean status, string machineLabel);
    public delegate void PrintParamsGetEventHandler(string machineCode, PrintParamsBean printParams);
    public delegate void PrintParamsSetEventHandler(string machineCode);
    public delegate void StartSupplyInkEventHandler(string machineCode);
    public delegate void StopSupplyInkEventHandler(string machineCode);
    public delegate void StartPrintEventHandler(string machineCode, string info);
    public delegate void StopPrintEventHandler(string machineCode);

    public class EventBus
    {
        public static event ClientLoginEventHandler OnLoginHandler;
        public static event ClientLogoutEventHandler OnLogoutHandler;
        public static event ServerSendMsgEventHandler OnSendMsgHandler;
        public static event ClientStatusEventHandler OnStatusRefreshHandler;
        public static event PrintParamsGetEventHandler OnPrintParamsGetHandler;
        public static event PrintParamsSetEventHandler OnPrintParamsSetHandler;
        public static event StartSupplyInkEventHandler OnStartSupplyInkHandler;
        public static event StopSupplyInkEventHandler OnStopSupplyInkHandler;
        public static event StartPrintEventHandler OnStartPrintHandler;
        public static event StopPrintEventHandler OnStopPrintHandler;

        public static void OnLogout(string machineCode)
        {
            OnLogoutHandler?.Invoke(machineCode);
        }

        public static void SendMsgHandler(string machineCode, Message msg)
        {
            //Log.Logger.Info("SendMsgHandler");
            OnSendMsgHandler?.Invoke(machineCode, msg);
        }

        internal static void OnStartSupplyInk(string machineCode)
        {
            OnStartSupplyInkHandler?.Invoke(machineCode);
        }

        internal static void OnStopSupplyInk(string machineCode)
        {
            OnStopSupplyInkHandler?.Invoke(machineCode);
        }

        internal static void OnStartPrint(string machineCode, string info)
        {
            OnStartPrintHandler?.Invoke(machineCode, info);
        }

        internal static void OnStopPrint(string machineCode)
        {
            OnStopPrintHandler?.Invoke(machineCode);
        }

        internal static void OnLogin(string machineCode, string machineLabel, IChannel channel)
        {
            OnLoginHandler?.Invoke(machineCode, machineLabel, channel);
        }

        internal static void OnGetPrintParams(string machineCode, PrintParamsBean printParams)
        {
            OnPrintParamsGetHandler?.Invoke(machineCode, printParams);
        }

        internal static void OnSetPrintParams(string machineCode)
        {
            OnPrintParamsSetHandler?.Invoke(machineCode);
        }

        internal static void OnStatusRefresh(string machineCode, StatusBean data, string machineLabel)
        {
            OnStatusRefreshHandler?.Invoke(machineCode, data, machineLabel);
        }
    }
}